document.write('<script type="text/javascript" src="../../js/tableScoll.js"></script>');
//ajax 通用方法
$(document).ready(function () {  

	$("#storeModify").click(function(){
		var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})  
		if(value.split(",").length > 2){
			alert("只能选择一个设备进行修改！");
			return;
		}
		if(value == ""){
			alert("请选择一个设备进行修改！");
			return;
		}
		var params = "id=" + value.substring(0,value.length-1);
		window.location.href="./storeAction_modifyStoreSearch.action?array=" + value.substring(0,value.length-1);
	});
	
	
	
	$("#storeAdjust").click(function(){
		var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})  
		if(value.split(",").length > 2){
			alert("只能选择一个设备进行调整！");
			return;
		}
		if(value == ""){
			alert("请选择一个设备进行调整！");
			return;
		}
		var params = "id=" + value.substring(0,value.length-1);
		window.location.href="./storeAction_adjustStoreSearch.action?array=" + value.substring(0,value.length-1);
	});
	
	
	$("#stDepartMent").change(function(){
		var params = "array=" + $("#stDepartMent").attr("value");
		$.ajax({  
            url:'./storeAjaxAction_queryAdminfo.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
				 	if(data !=null){
				 		 $("#stContactEmployer").find('option').remove();
				 		 $.each(data,function(key,bean) {
				    	 	$("#stContactEmployer").append("<option value="+bean.stAdminNumber+">"+ bean.stAdminEmployer +"</option>"); 
			    	 	 });
			 	 	}else{
			 	 		alert("搜索失败！");
			 	 	}
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	$("#stArea").change(function(){
		var params = "array=" + $("#stArea").attr("value");
		$.ajax({  
            url:'./storeAjaxAction_queryMerchantInfo.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
				 	if(data !=null){ 
				 		 $("#stMerchantId").find('option').remove();
				 		 $.each(data,function(key,bean) {
				    	 	$("#stMerchantId").append("<option value="+bean.stMerchantId+">"+ bean.stMerchantName +"</option>"); 
			    	 	 });
			 	 }
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	$("#storeAdjustSave").click(function(){
		var params = $("#stState").attr("name") + "=" + $("#stState").attr("value")
		+ "&" + $("#stStoreLocation").attr("name") + "=" + $("#stStoreLocation").attr("value")
		+ "&" + $("#stMerchantId").attr("name") + "=" + $("#stMerchantId").attr("value");
		$.ajax({  
            url:'./storeAjaxAction_checkAdjust.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
			 	if(data !=null){ 
			 		 $.each(data,function(key,value) {
			    	 	alert(value);
		    	 	 });
		 	 	}else{
		 	 		$("#adjustStoreForm").submit();
		 	 	}
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	$("#storeParmeterModify").click(function(){
		var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})  
		if(value.split(",").length > 2){
			alert("只能选择一个部件进行修改！");
			return;
		}
		if(value == "" || value == null){
			alert("请选择一个部件修改！");
			return;
		}
		var params = "bean.stId=" + value.substring(0,value.length-1) ;
		var param = "";
    	$("input[type='text'][id='_cparam']").map(function() {
		   	  if(this.value != null && this.value != ""){
  				  param = param + this.name + "=" + this.value + "&";
  			  }else{
  				  param = param + this.name+ "=" +null + "&";
  			  }		  
    	});
    	params = params + "&" +param;
		$.ajax({  
            url:'./storeParmeterAjax_modifyStoreParmeter.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
			 	if(data !=null){ 
			 		alert(data.message);
			 		 window.location.reload();
		 	 	}
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	
	$("#storeParmeterDelete").click(function(){
		var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})  
		if(value.split(",").length > 2){
			alert("只能选择一个部件进行修改！");
			return;
		}
		if(value == ""){
			alert("请选择一个部件修改！");
			return;
		}
    	params ="array=" + value.substring(0,value.length-1);
		$.ajax({  
            url:'./storeParmeterAjax_deleteStoreParmeter.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
			 	if(data !=null){ 
			 		alert(data.message);
			 		 window.location.reload();
		 	 	}
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	
	$("#storeParmeterSave").click(function(){
		var params = "";
    	$("input[type='text'][id='_cparam']").map(function() {
		   	  if(this.value != null && this.value != ""){
  				  params = params + this.name + "=" + this.value + "&";
  			  }else{
  				  if(this.name == "stStoreType"){
  					 	alert("部件类型不能为空！");
  				  		return;    
  				  }
  				  if(this.name == "stStoreNo"){
  					 	alert("部件编号不能为空！");
  				  		return;    
  				  }
  				  if(this.name == "stStoreName"){
  					 	alert("部件名称不能为空！");
  				  		return;    
  				  }
  			  }		  
    	});
		$.ajax({  
            url:'./storeParmeterAjax_saveStoreParmeter.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
			 	if(data !=null){ 
			 		alert(data.message);
			 		 window.location.reload();
		 	 	}
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
});  

 
